home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
scope
/
001-025
/
scopedisk6
/
extract
/
extractfont.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-18
|
5KB
|
185 lines
#include <exec/types.h>
#include <graphics/text.h>
#include <graphics/gfxbase.h>
#include <functions.h>
#include <stdio.h>
struct GfxBase *GfxBase = 0;
struct Library *DiskfontBase = 0;
struct TextFont *FontPtr = 0;
struct TextAttr NewFont = {
NULL, /* Font Name */
0, /* Font Height */
FS_NORMAL, /* Style */
FPF_DESIGNED }; /* Preferences */
char name[250];
main (argc, argv)
int argc;
char **argv;
{
FILE *fp;
int i, j, count;
UWORD *w;
ULONG *l;
if (argc != 4) {
printf ("Usage: %s fontname fontsize outfile\n",argv[0]);
printf ("(ie. %s diamond.font 20 DIAMOND.c)\n", argv[0]);
exit (0);
}
NewFont.ta_Name = (STRPTR)argv[1];
NewFont.ta_YSize = atoi (argv[2]);
if (( GfxBase = (struct GfxBase *)OpenLibrary ("graphics.library", LIBRARY_VERSION)) == NULL)
Quit ("Couldn't open graphics.library");
if (( DiskfontBase = OpenLibrary ("diskfont.library", LIBRARY_VERSION)) == NULL)
Quit ("Couldn't open diskfont.library");
if (( FontPtr = (struct TextFont *)OpenDiskFont (&NewFont)) == NULL)
Quit ("Couldn't open small.font");
if (!( fp = fopen (argv[3], "w")))
Quit ("Couldn't open outfile");
strcpy (name, "");
strncat (name, argv[1], strlen (argv[1]) - 5);
strcat (name, "Font");
name[0] = toupper (name[0]);
fprintf (fp, "#include <graphics/text.h>\n\n");
fprintf (fp, "extern char fontname[];\n");
fprintf (fp, "extern UWORD CharData[];\n");
fprintf (fp, "extern ULONG CharLoc[];\n");
fprintf (fp, "extern UWORD CharSpace[];\n");
fprintf (fp, "extern UWORD CharKern[];\n\n");
fprintf (fp, "struct TextFont %s = {\n", name);
fprintf (fp, "\t{\t\t/* Message\t*/\n");
fprintf (fp, "\t\t{\t\t/* Node\t*/\n");
fprintf (fp, "\t\t\tNULL,\t\t/* ln_Succ\t*/\n");
fprintf (fp, "\t\t\tNULL,\t\t/* ln_Pred\t*/\n");
fprintf (fp, "\t\t\tNT_FONT,\t/* ln_Type\t*/\n");
fprintf (fp, "\t\t\t0,\t\t/* ln_Pri\t*/\n");
fprintf (fp, "\t\t\tfontname,\t/* ln_Name\t*/\n");
fprintf (fp, "\t\t},\n");
fprintf (fp, "\t\tNULL,\t\t\t/* mn_ReplyPort\t*/\n");
fprintf (fp, "\t\tsizeof (%s) +\n", name),
fprintf (fp, "\t\tsizeof (fontname) +\n"),
fprintf (fp, "\t\tsizeof (CharData) +\n"),
fprintf (fp, "\t\tsizeof (CharLoc) +\n"),
fprintf (fp, "\t\tsizeof (CharSpace) +\n"),
fprintf (fp, "\t\tsizeof (CharKern),\t/* mn_Length\t*/\n", name);
fprintf (fp, "\t},\n");
fprintf (fp, "\t%u,\t\t/* tf_YSize\t*/\n", FontPtr->tf_YSize);
fprintf (fp, "\t%u,\t\t/* tf_Style\t*/\n", FontPtr->tf_Style);
fprintf (fp, "\t%u,\t\t/* tf_Flags\t*/\n", FontPtr->tf_Flags);
fprintf (fp, "\t%u,\t\t/* tf_XSize\t*/\n", FontPtr->tf_XSize);
fprintf (fp, "\t%u,\t\t/* tf_Baseline\t*/\n", FontPtr->tf_Baseline);
fprintf (fp, "\t%u,\t\t/* tf_BoldSmear\t*/\n", FontPtr->tf_BoldSmear);
fprintf (fp, "\t0,\t\t/* tf_Accessors\t*/\n");
fprintf (fp, "\t%u,\t\t/* tf_LoChar\t*/\n", FontPtr->tf_LoChar);
fprintf (fp, "\t%u,\t\t/* tf_HiChar\t*/\n", FontPtr->tf_HiChar);
fprintf (fp, "\t(APTR)&CharData,/* tf_CharData\t*/\n");
fprintf (fp, "\t%u,\t\t/* tf_Modulo\t*/\n", FontPtr->tf_Modulo);
fprintf (fp, "\t(APTR)&CharLoc,\t/* tf_CharLoc\t*/\n");
fprintf (fp, "\t(APTR)&CharSpace,/*tf_CharSpace\t*/\n");
fprintf (fp, "\t(APTR)&CharKern,/* tf_CharKern\t*/\n");
fprintf (fp, "};\n\n");
fprintf (fp, "char fontname[] = \"%s\";\n\n", argv[1]);
fprintf (fp, "UWORD CharData[] = {\n");
w = (UWORD *)FontPtr->tf_CharData;
for (i=0; i<FontPtr->tf_YSize; i++) {
count = 0;
for (j = 0; j <FontPtr->tf_Modulo / 2; j++) {
if (count == 0) fprintf (fp, "\t");
fprintf (fp, "0x%04x,", *w++);
count++;
if (count == 8) {
count = 0;
fprintf (fp, "\n");
}
}
if (count) {
fprintf (fp, "\n");
}
}
fprintf (fp, "};\n\n");
fprintf (fp, "ULONG CharLoc[] = {\n");
l = (ULONG *)FontPtr->tf_CharLoc;
count = 0;
for (i=FontPtr->tf_LoChar; i<=FontPtr->tf_HiChar; i++) {
if (count == 0) fprintf (fp, "\t");
fprintf (fp, "0x%08x,", *l++);
count++;
if (count == 4) {
count = 0;
fprintf (fp, "\n");
}
}
if (count) {
fprintf (fp, "\n");
}
fprintf (fp, "};\n\n");
fprintf (fp, "UWORD CharSpace[] = {\n");
w = (UWORD *)FontPtr->tf_CharSpace;
count = 0;
for (i=FontPtr->tf_LoChar; i<=FontPtr->tf_HiChar; i++) {
if (count == 0) fprintf (fp, "\t");
fprintf (fp, "0x%04x,", *w++);
count++;
if (count == 8) {
count = 0;
fprintf (fp, "\n");
}
}
if (count) {
fprintf (fp, "\n");
}
fprintf (fp, "};\n\n");
fprintf (fp, "UWORD CharKern[] = {\n");
w = (UWORD *)FontPtr->tf_CharKern;
count = 0;
for (i=FontPtr->tf_LoChar; i<=FontPtr->tf_HiChar; i++) {
if (count == 0) fprintf (fp, "\t");
fprintf (fp, "0x%04x,", *w++);
count++;
if (count == 8) {
count = 0;
fprintf (fp, "\n");
}
}
if (count) {
fprintf (fp, "\n");
}
fprintf (fp, "};\n");
fclose (fp);
Quit (NULL);
}
Quit (message)
char *message;
{
if (FontPtr) CloseFont (FontPtr);
if (DiskfontBase) CloseLibrary (DiskfontBase);
if (GfxBase) CloseLibrary (GfxBase);
if (message)
printf ("error: %s\n", message);
exit (0);
}